/**
 * 请求配置
 */
import axios from "axios";
import { message } from "antd";
import store from "@/redux";
import variables from "@/utils/global/variables";
/**
 *
 * @param {Object} data - axios参数配置
 */
export const Request = data =>
  new Promise((resolve, reject) => {
    // axios配置
    const service = axios.create({
      baseURL: variables.BaseURL,
      headers: {
        token: store.getState().userInfo.token
      },
      timeout: 5000
    });
    // 请求服务
    service(data)
      .then(({ status, data: res }) => {
        // http请求状态是否成功
        if (status === 200) {
          const { code, msg, data } = res;
          // 业务逻辑是否成功
          if (code === 1) {
            resolve(data);
          } else {
            message.error(msg);
            reject(res);
          }
        } else {
          reject(res);
        }
      })
      .catch(error => {
        reject(error);
      });
  });
